import { getWinType } from '@/utils/app';
import setting from '@/config/setting.config';
// xs   < 576px;
// sm	≥576px;
// md	≥768px;
// lg	≥992px;
// xl	≥1200px;
// xxl	≥1600px;
export type winType = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
export type Locale = 'zh-cn' | 'en-us';
export interface AppTypes {
    collapsed: boolean;//菜单收缩
    winType: winType;//屏幕大小
    locale: Locale;//语言设置
    cacheds: string[];//缓存页面
    themeColor: string;//主题颜色
}
const winType = getWinType(window.innerWidth);
const state: AppTypes = {
    collapsed: winType === 'sm' || winType === 'xs',
    winType: winType,
    locale: window.localStorage.getItem('locale') as Locale || 'zh-cn',
    cacheds: [],
    themeColor: setting.defaultThemeColor
};
const mutations = {
    SET_COLLAPSED(state: AppTypes, val: boolean) {
        state.collapsed = val;
    },
    SET_WINDOW_TYPE(state: AppTypes, val: any) {
        state.winType = val;
    },
    SET_LOCALE(state: AppTypes, val: Locale) {
        state.locale = val;
    },
    SET_CACHEDS_PUSH(state: AppTypes, val: string) {
        if (val && state.cacheds.indexOf(val) === -1) {
            state.cacheds.push(val);
        }
    },
    SET_CACHEDS_SPLICE(state: AppTypes, val: string) {
        const index = state.cacheds.indexOf(val);
        if (index === -1) return;
        state.cacheds.splice(index, 1);
    },
    SET_THEME_COLOR(state: AppTypes, val: string) {
        state.themeColor = val;
    }
};
const actions = {
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
};
